import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_learn_vi/src/bean/bean_mine_uestion.dart';
import 'package:flutter_learn_vi/src/page/home/new/study_my_error_page.dart';
import 'package:flutter_learn_vi/src/page/topic/topic_catar_select_page.dart';
import 'package:flutter_learn_vi/src/page/topic/topic_select_page.dart';
import 'package:flutter_learn_vi/src/utils/navigator_utils.dart';
import 'package:flutter_learn_vi/src/utils/toast_utils.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/13.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class StudyItemV4Widget extends StatelessWidget {
  final StudyModelItemBean itemBean;
  final String iconPath;
  final double width;
  final double radius;
  final double pading;
  final int index;

  StudyItemV4Widget(this.itemBean, this.iconPath, this.index,
      {this.width = 33, this.radius = 8, this.pading = 0});

  @override
  Widget build(BuildContext context) {
    return InkWell(
      child: buildClipRRect(itemBean),
      onTap: () {
        Widget page;

        if (itemBean.pageType == 1) {
          page = itemBean.page;
        } else {
          if (itemBean.nodeType == "APPJUMP") {
            page = MyErrorPage();
          } else {
            if (itemBean.nodeValue != null) {
              page = TopicSelectPage(
                pageTitle: "${itemBean.nodeName}",
                categoryOne: itemBean.nodeValue,
              );
            } else if (itemBean.nodeValues != null &&
                itemBean.nodeValues.length > 0) {
              page = TopicCatarSelectTwoPage(
                  pageTitle: "${itemBean.nodeName}",
                  nodeValues: itemBean.nodeValues);
            } else {
              //暂无详情
              ToastUtils.showToast("暂无详情");
              return;
            }
          }
        }
        NavigatorUtils.pushPage(
          context,
          page,
        );
      },
    );
  }

  Widget buildClipRRect(StudyModelItemBean itemBean) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Container(
          margin: EdgeInsets.only(left: 4, right: 4, top: 12),
          padding: EdgeInsets.all(pading),
          child: Image.asset(
            iconPath,
            width: 33,
          ),
        ),
        Container(
          margin: EdgeInsets.only(top: 6),
          child: Text(
            "${itemBean.nodeName}",
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(
                fontWeight: FontWeight.w500,
                color: Colors.blueGrey,
                fontSize: 12),
          ),
        ),
      ],
    );
  }
}
